<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import="java.text.DateFormat" %>
<%@ page import="com.broadvision.ssp.common.TaskState" %>
<%@ page import="com.broadvision.ssp.client.workflow.TaskInstance" %>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<% String ctxPath = request.getContextPath(); %>

<jsp:useBean id="processInstanceTasksForm"
          class="com.broadvision.process.tools.action.process.ProcessInstanceTasksForm"
          scope ="session"/>
<script language="javascript" src="<%=request.getContextPath()%>/mt/js/date.js"></script>
<script language="javascript" src="<%=request.getContextPath()%>/bp/js/user_popup_funcs.js"></script>

<SCRIPT>

var myAct = null;
var itemI = -1;

function browseCandidates() {
  var popupUrl = '<html:rewrite page="/bp/processInstanceBrowseCandidates.do"/>';
  var windowFeatures = 'width=500,height=300,scrollbars=yes,resizable=yes';
  var popupWindow = window.open(popupUrl, "browseCandidates", windowFeatures);
  if (popupWindow != null) {
    if (popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

function selectPerformer(act,i) {
  myAct = act;
  itemI = i;
  var doMultiSelect = true;
  var selectedusers = '&selected=';
<%
  String[] candidates = processInstanceTasksForm.getCandidates();
  if (candidates != null) {
    for (int i = 0; i < candidates.length;i++) {
%>
      selectedusers += '<%=candidates[i] %>';
<%
      if (i < candidates.length - 1) {
%>
        selectedusers += '%24%23@!';
<%
      }
    }
  }
  else {
%>
    doMultiSelect = false;
    with(document.processInstanceTasksForm) {
      if (performerUserName[0] == null)
        selectedusers += performerUserName.value;
      else
        selectedusers += performerUserName[i].value;
    }
<%
  }
%>
  var popupUrl = '';
  if (doMultiSelect == true) {
    popupUrl = '<html:rewrite page="/mt/userMultiSearchPopup.do"/>';
  }
  else {
    popupUrl = '<html:rewrite page="/mt/userSearchPopup.do"/>';
  }
  if (popupUrl.indexOf("?") < 0) {
    popupUrl += "?";
  }
  else {
    popupUrl += "&";
  }
  popupUrl += '&parentFormName=processInstanceTasksForm&parentFieldName=performerUserName';
  popupUrl += selectedusers;
  var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
  var popupWindow = window.open(popupUrl, "changePerformer", windowFeatures);
  if (popupWindow != null) {
    if (popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

function mySubmit(){
  with(document.processInstanceTasksForm) {
    action='<c:url value="/bp/processInstancePerformer.do"/>';
    if (performerUserName[0] == null)
      performer = performerUserName;
    else
      performer = performerUserName[i];
    if (performer == null)
      return false;
    var iName = performer.value;
    iName = iName.replace(/ /g, "");
    if (iName.length == 0) {
      alert('<bean:message key="bp.process.processInstanceTaskDetail.alert.performer" bundle="bp.messages"/>');
      return false;
    }
    assignee.value = iName;
    taskIndex.value = itemI;
    myAction.value = myAct;
    submit();
  }
  return false;
}

function setUserAlias(formName, fieldName, fieldValue) {
  if (fieldValue == null)
    return;
  var refreshUrl = null;
  setFieldValue(refreshUrl, formName, fieldName, fieldValue);
  mySubmit();
}

function setSelectedUsers(formName, fieldName, users) {
  setUserAlias(formName, fieldName, users[0]);
  var thisForm = document.forms[formName];
  var elements = thisForm.elements;
}

function doReset(myform) {
  myform.action = '<html:rewrite page="/bp/processInstanceTaskDetail.do"/>';
  myform.submit();
}

function doCancel(myform) {
  myform.action = '<html:rewrite page="/bp/processInstanceTasks.do"/>';
  myform.submit();
}

</SCRIPT>

<%
  java.util.HashMap map= new java.util.HashMap();
  String instanceOid = request.getParameter("instanceOid");
  if (instanceOid != null && instanceOid.length() > 0) {
    map.put("instanceOid",instanceOid);
  }
  map.put("currentTask",request.getParameter("currentTask"));
  pageContext.setAttribute("pagetabParam",map);

  TaskInstance taskInstance =
                         (TaskInstance)(processInstanceTasksForm.getTaskMap()) .
                               get(processInstanceTasksForm.getCurrentTask());
%>
    <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.process.processInstance.contentArea" bundle="bp.messages"/>">
      <html:form action="/bp/processInstanceTaskSave.do">
      <html:hidden property="currentTask"/>
      <html:hidden name="processInstanceTasksForm" property="instanceOid"/>
<tr>
        <td valign="top" width="100%">
          <div class="pageTitle"><bean:write name="processInstanceTasksForm" property="currentMinorTask" />
          </div>
          <%@include file="/mc/common/pagetab.jsp" %>
<div class="breadcrumb">
          <html:link page="/bp/processInstanceTasks.do"  paramId="instanceOid" paramName="processInstanceTasksForm"  paramProperty="instanceOid"><bean:write name="bpProcessInstanceForm" property="processInstance.customId" /></html:link>&nbsp;>&nbsp;<bean:write name="processInstanceTasksForm" property="currentMinorTask" /></div>
          <div class="pageSubtitle">
            <span class="left"><bean:message key="bp.process.processInstanceTaskDetail.subtitle" bundle="bp.messages"/></span>
          </div>
          <table class="dataTable" border="0" cellspacing="0" cellpadding="0" summary="<bean:message key="bp.process.processInstanceTaskDetail.summary" bundle="bp.messages"/>"  width="100%">
            <tr><td class="errorMessage" colspan="2"><html:errors bundle="bp.messages"/></td></tr>
            <% if (taskInstance != null) {
                   pageContext.setAttribute("taskInstance", taskInstance); %>

            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.name" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                    <bean:write name="processInstanceTasksForm" property="currentMinorTask" />
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.type" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                 <bean:message key="<%=\"bp.process.instance.tasktype.\"+ taskInstance.getTaskType()%>" bundle="bp.messages"/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.definedPerformer" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
<%String perf1= taskInstance.getDefinedPerformer()==null?"":taskInstance.getDefinedPerformer().getPerformer();
		                     if(perf1.equalsIgnoreCase("LaunchUser"))
		                     {%>
		                     <bean:message key="bp.process.processInstanceTaskDetail.LaunchUser" bundle="bp.messages"/>
		                     <%}
		                     else{%>
		                      <%=perf1%>
		                    <% }%>
            <% if (candidates!=null) { %>
                 <a href='#' onclick="browseCandidates();">
                  <img src="<%=request.getContextPath()%>/bp/images/action/icon_view.gif" width="15" height="15" border="0" alt='<bean:message key="image.alt.candidates" bundle="bp.messages"/>' title='<bean:message key="image.alt.candidates" bundle="bp.messages"/>' valign="bottom"></a><%}%></td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.performerType" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                     <bean:write name="processInstanceTasksForm"  property="performerType"/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.instruction" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                    <%= taskInstance.getInstruction()%>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.status" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                    <bean:message key='<%="bp.process.task.state."+ taskInstance.getState().getIntCode()%>' bundle="bp.messages"/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.priority" bundle="bp.messages"/></td>
                <td valign="top"  class="labelField" width="40%">
                    <bean:message key='<%="bp.process.instance.priority."+ taskInstance.getPriority()%>' bundle="bp.messages"/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label" width="18%"><bean:message key="bp.process.processInstanceTaskDetail.dueDate" bundle="bp.messages"/></td>
                <% if (processInstanceTasksForm.getDueDate()==null) { %>
                <td valign="top"  class="labelField" width="40%">&nbsp;
                </td>
                <% } else { %>
                <td valign="top" wrap class="labelField" width="40%">
                <bvhtml:date name="processInstanceTasksForm" property="dueDate"
                   onChangeMonth="onChangeMonth" onChangeYear="onChangeYear" noblank="true"/>
                    <a href="JavaScript:datePopup(
                        '<html:rewrite page="/mt/calendar.do"/>',
                        'processInstanceTasksForm','dueDate')">
    <img src="<%= ctxPath %>/bp/images/action/calendar.gif" width="22" height="22"
    alt="<bean:message key="bp.process.processInstanceSearch.chooseDate"  bundle="bp.messages"/>"
    border="0" align="absmiddle"/></a>&nbsp;<%= DateFormat.getTimeInstance(DateFormat.SHORT).format(taskInstance.getDueDate())%>
                </td>
                <% } %>
            </tr>
            <% } //if null%>
        </table>
    <% if (processInstanceTasksForm.getDueDate()!= null) { %>
      <div class="pageButtonWrap" align="right">
        <input type="button" name="resetData" class="pageButton"
          onClick="doReset(this.form);"
          value='<bean:message key="button.reset" bundle="bp.messages"/>'>
        &nbsp;
        <input type="button" name="cancelData" class="pageButton"
          onClick="doCancel(this.form);"
          value='<bean:message key="button.cancel" bundle="bp.messages"/>'>
        <input type="submit" class="pageButton" value="<bean:message key="button.save" bundle="bp.messages"/>" onclick="javascript:document.processInstanceTasksForm.submit();return false;">
      </div>
<% } %>
      <% if (taskInstance!=null ) { %>
      <div class="pageSubtitle">
        <span class="left"><bean:message key="bp.process.processInstanceTaskDetail.itemSubtitle" bundle="bp.messages"/>
        </span>
        <span class="right">&nbsp;</span>
      </div>
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean:message key="bp.process.processInstanceTaskDetail.itemSummary" bundle="bp.messages"/>" width="100%">
<input type="hidden" name="assignee" value="" />
<input type="hidden" name="taskIndex" value="0" />
<input type="hidden" name="myAction" value="" />
        <tr class="listHeader">
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.columnName" bundle="bp.messages"/></th>
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.performer" bundle="bp.messages"/></th>
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.columnStatus" bundle="bp.messages"/></th>
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.columnType" bundle="bp.messages"/></th>
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.columnStartTime" bundle="bp.messages"/></th>
          <th id="TaskName" align="left"><bean:message key="bp.process.processInstanceTaskDetail.columnCompletionTime" bundle="bp.messages"/></th>
          <th id="Actions" align="left"><bean:message key="bp.process.processInstanceSearch.action" bundle="bp.messages"/></th>
        </tr>
        <logic:iterate id="taskItem" name="processInstanceTasksForm"
          property="dataForm.taskList" indexId="i"
          type="java.util.Map" >
          <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
            <td headers="Name">
                <bean:write name="taskItem" property="name"/>
            </td>
            <td headers="performer">
<%
  boolean viewonly = ((Boolean)taskItem.get("viewOnly")).booleanValue();
  if (!viewonly && taskItem.get("performer") != null) {
%>
              <input type="text"  name="performerUserName" value="<%= taskItem.get("performer")%>" size="20" maxlength="128" />
<%
  }
  else if (!viewonly && taskItem.get("performer") == null) {
%>
              <input type="text"  name="performerUserName" value="<bean:message key="bp.process.processInstanceTaskDetail.performer.invalid" bundle="bp.messages"/>" size="20" maxlength="128" />
<%
  }
  else if (taskItem.get("performer") != null) {
%>
              <%= taskItem.get("performer")%>
<%
  }
  else {
%>
              &nbsp;
<%
  }
%>
            </td>
            <td headers="state">
                <bean:message key='<%="bp.process.task.state."+ ((TaskState)taskItem.get("state")).getIntCode()%>' bundle="bp.messages"/>
            </td>
            <td headers="taskType">
                <bean:message key='<%="bp.process.instance.tasktype."+ taskItem.get("taskType")%>' bundle="bp.messages"/>
            </td>
            <td headers="startTime">
                <bean:write name="taskItem" property="startTime" formatKey="format.datetime.short" bundle="mc.messages"/>
            </td>
            <td headers="endTime">
                <bean:write name="taskItem" property="endTime" formatKey="format.datetime.short" bundle="mc.messages"/>
            </td>
            <td headers="Actions">
<%
  if (!viewonly) {
    if (TaskState.TASK_AVAILABLE!=(TaskState)taskItem.get("state")) {
%>
              <a href="#" onClick="return selectPerformer('reAssign',<%=i%>);">
                <img src="<%= ctxPath %>/bp/images/action/icon_reassign.gif" width="15" height="15" border="0" alt="<bean:message key="bp.process.processInstanceTaskDetail.alt.reAssign" bundle="bp.messages"/>" title="<bean:message key="bp.process.processInstanceTaskDetail.alt.reAssign" bundle="bp.messages"/>"></a>
<%
    }
    else {
%>
              <a href="#" onClick="selectPerformer('groupAny2person',<%=i%>);">
                <img src="<%= ctxPath %>/bp/images/icons/group.gif" width="15" height="15" border="0" alt="<bean:message key="bp.process.processInstanceTaskDetail.alt.groupAnyAssign" bundle="bp.messages"/>" title="<bean:message key="bp.process.processInstanceTaskDetail.alt.groupAnyAssign" bundle="bp.messages"/>"></a>
<%
    }
  }
  else {
    if (TaskState.TASK_AVAILABLE!=(TaskState)taskItem.get("state")) {
%>
              <img src="<%= ctxPath %>/bp/images/action/icon_reassign.gif" width="15" height="15" border="0" alt="<bean:message key="bp.process.processInstanceTaskDetail.alt.reAssign" bundle="bp.messages"/>" title="<bean:message key="bp.process.processInstanceTaskDetail.alt.reAssign" bundle="bp.messages"/>">&nbsp;
<%
  }
  else {
%>
              <img src="<%= ctxPath %>/bp/images/icons/group.gif" width="15" height="15" border="0" alt="<bean:message key="bp.process.processInstanceTaskDetail.alt.groupAnyAssign" bundle="bp.messages"/>" title="<bean:message key="bp.process.processInstanceTaskDetail.alt.groupAnyAssign" bundle="bp.messages"/>">
<%
    }
  }
%>
            </td>
          </tr>
        </logic:iterate>
      </table>
      <% } //length > 0%>
        </td>
      </tr>
  </html:form>
    </table>

<script>
if (document.processInstanceTasksForm.performerUserName != undefined){
document.processInstanceTasksForm.performerUserName.readOnly = !document.processInstanceTasksForm.performerUserName.readOnly;}
</script>
